//
//  FatherViewController.m
//  UI_豆瓣
//
//  Created by dllo on 15/11/4.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "FatherViewController.h"
#import "MoviesViewController.h"
#import "NineViewController.h"
@interface FatherViewController ()

@property(nonatomic, assign)BOOL isSelected;
@property(nonatomic, retain)MoviesViewController *movieVC;
@property(nonatomic, retain)NineViewController *nineVC;
@property(nonatomic, retain)UIButton *button;

@end

@implementation FatherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor whiteColor];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(0, 0, 40, 43);
    [self.button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.button setBackgroundImage:[UIImage imageNamed:@"btn_nav_collection@2x.png"] forState:UIControlStateNormal];
    
    //设置标题
    self.navigationItem.title = @"电影";
    
    
    //右侧按钮
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithCustomView:self.button] autorelease];
 
    
   
    //九宫格
    self.nineVC = [[NineViewController alloc]init];
    [self.view addSubview:self.nineVC.view];
    [self addChildViewController:self.nineVC];
    
    
    //添加子视图控制器
    //当前self作为容器视图控制器
    //电影抽屉
    self.movieVC = [[MoviesViewController alloc]init];
    [self.view addSubview:self.movieVC.view];
     [self addChildViewController:self.movieVC];
    
    
}


-(void)buttonAction:(UIButton *)but
{
    if (but.selected == NO) {
        
        
        //动画效果
        [UIView transitionFromView:self.movieVC.view toView:self.nineVC.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
            
            [self.button setBackgroundImage:[UIImage imageNamed:@"btn_nav_list@2x.png"] forState:UIControlStateNormal];
        }];
        
    }else{
        //        [self.view bringSubviewToFront:self.collectionVC.view];
        [UIView transitionFromView:self.nineVC.view toView:self.movieVC.view duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
            
            
             [self.button setBackgroundImage:[UIImage imageNamed:@"btn_nav_collection@2x.png"] forState:UIControlStateNormal];
        }];
        
    }
    
    
    but.selected = !but.selected;
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
